package com.njtech.pet.service.impl;

import com.njtech.pet.dao.PersonDao;
import com.njtech.pet.entity.Person;
import com.njtech.pet.entity.User;
import com.njtech.pet.service.PersonService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Author:gm
 * Date:2020-03-31 23:33
 * Description:<描述>
 */

@Service
@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
public class PersonServiceImpl implements PersonService {
    @Autowired
    private PersonDao personDao;
    /**
     * 插入一条记录
     * @param person 自然人数据
     * @return 修改行数
     */
    @Override
    public int insert(Person person){
        return personDao.insert(person);
    }

    /**
     * 修改一条记录
     * @param person 自然人数据
     * @return 修改行数
     */
    @Override
    public int updateByPersonId(Person person){
        return personDao.updateByPersonId(person);
    }

    /**
     * 根据用户id查找他记录的所有自然人
     * @param user 用户Id不能为空
     * @return 集合
     */
    @Override
    public List<Person> selectByUserId(User user){
        return personDao.selectByUserId(user);
    }

    /**
     * 根据person id 查询
     * @param id person id
     * @return result
     */
    @Override
    public Person selectByPersonId(@Param("id")Integer id){
        return (Person) personDao.selectByPersonId(id);
    }
}
